package com.example.schoolhospitalsystem;


import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class UserInfoEditActivity extends AppCompatActivity {

    private EditText etName, etPhone, etPassword;
    private Button btnSaveInfo;
    private String userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_info_edit);

        // 获取用户ID
        Intent intent = getIntent();
        userId = intent.getStringExtra("userId");

        etName = findViewById(R.id.et_name);
        etPhone = findViewById(R.id.et_phone);
        etPassword = findViewById(R.id.et_password);
        btnSaveInfo = findViewById(R.id.btn_save_info);

        // 保存信息按钮点击事件
        btnSaveInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = etName.getText().toString().trim();
                String phone = etPhone.getText().toString().trim();
                String password = etPassword.getText().toString().trim();

                if (updateUserInfo(userId, name, phone, password)) {
                    Toast.makeText(UserInfoEditActivity.this, "个人信息修改成功", Toast.LENGTH_SHORT).show();
                    finish();
                } else {
                    Toast.makeText(UserInfoEditActivity.this, "个人信息修改失败", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private boolean updateUserInfo(String userId, String name, String phone, String password) {
        // 这里应该连接数据库更新用户信息
        // 简化示例，直接返回更新成功
        return true;
    }
}